# -*- coding: utf-8 -*-

import morfologik
import stemmer
import string

class QueryParser :
    def __init__(self, word_processor=None) :
        self.__word_processor = word_processor
                
    def __boolean_to_base_form(self, query) :
        alternatives = query.split(' ')
        bases = []
        for alt in alternatives :
            words = alt.split('|')
            base = []
            for word in words :
                base.append(self.__word_processor.process(word))
            bases.append(base)
        return bases
        
    def parse(self, query) :
        result = []
        if len(query) > 0 :
            query = query.strip()
            if query[0] == "\"" :
                string.translate(query, None, '\"')
                result.append(query)
            else :
                result = self.__boolean_to_base_form(query)
        return result

if __name__ == "__main__" :
    stemmer = stemmer.Stemmer()
    lemmatizer = morfologik.Morfologik()
    parser = QueryParser(lemmatizer)
    print parser.parse("języczek|języczuszek|język rosyjski|rosyjziuchny|ruszczyzna")
    print parser.parse("\"antysemityzm wśród establishmentu brytyjskiego\"")
    print parser.parse("zygmunt ii august")
